import React, { Component, Fragment } from 'react';
import { Card, Descriptions, Image, Button, Space, Popover } from 'antd'
import { connect } from 'dva';
import constant from '../../constant/constant'

class VerificationExaminationPage extends Component {
    constructor(props) {
        super(props)
    }

    componentDidMount() {
        this.props.dispatch({
            type: "application/getVerificationMechanismInformation",
            data: { verificationApplicationId: this.props.verification.technologyId }
        })
    }

    goToNextProcess = () => {
        this.props.dispatch({
            type:"application/goToNextProcess",
            data:{
                verificationApplicationId:this.props.verification.technologyId
            }
        })
    }

    renderNextButton = information => {
        if(information.reportexaminationStatus == 2){
            return(
                <Button style={{marginTop:30}} type="primary" onClick={this.goToNextProcess}>下一步</Button>
            )
        }
    }

    render() {
        return (
            <Fragment>
                <Descriptions column={1} bordered={true} title={this.props.verificationInformation.reportexaminationStatus == 1 ? <p>正在审查中</p> : (this.props.verificationInformation.reportexaminationStatus == 0) ?
                    <Popover content={this.props.verificationInformation.reportreason}><p>审查未通过</p></Popover> : <p>审查通过</p>
                } >
                    <Descriptions.Item label="验证机构">{this.props.verificationInformation.mechanismName}</Descriptions.Item>
                    <Descriptions.Item label="验证报告">{this.props.verificationInformation.verificationReport ? <a href={constant.serverUrl + constant.fileUrl.mechanismUrl + this.props.verificationReport}>{this.props.verificationInformation.verificationReport}</a> : "验证机构暂未上传"}</Descriptions.Item>
                    <Descriptions.Item label="验证声明">{this.props.verificationInformation.verificationStatement ? <a href={constant.serverUrl + constant.fileUrl.mechanismUrl + this.props.verificationStatement}> {this.props.verificationInformation.verificationStatement}</a> : "验证机构暂未上传"}</Descriptions.Item>
                </Descriptions>
                {this.renderNextButton(this.props.verificationInformation)}
            </Fragment>
        )
    }
}

const mapStateToProps = state => {
    let verificationInformation = state.application.verificationInformation
    let verification = state.application.verification
    return {
        verificationInformation,
        verification
    }
}

export default connect(mapStateToProps)(VerificationExaminationPage)